package com.meilele.dao.czh;

import com.meilele.entity.czh.FiveCommentaries;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FiveCommentariesMapper {
    @Delete({
        "delete from five_commentaries",
        "where commentaries_id = #{commentariesId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer commentariesId);

    @Insert({
        "insert into five_commentaries (commentaries_id, commentaries_time, ",
        "post_id, commentaries_name, ",
        "commentaries_content)",
        "values (#{commentariesId,jdbcType=INTEGER}, #{commentariesTime,jdbcType=TIMESTAMP}, ",
        "#{postId,jdbcType=INTEGER}, #{commentariesName,jdbcType=VARCHAR}, ",
        "#{commentariesContent,jdbcType=LONGVARCHAR})"
    })
    int insert(FiveCommentaries record);

    int insertSelective(FiveCommentaries record);

    @Select({
        "select",
        "commentaries_id, commentaries_time, post_id, commentaries_name, commentaries_content",
        "from five_commentaries",
        "where commentaries_id = #{commentariesId,jdbcType=INTEGER}"
    })
    @ResultMap("com.meilele.dao.czh.FiveCommentariesMapper.ResultMapWithBLOBs")
    FiveCommentaries selectByPrimaryKey(Integer commentariesId);
    @Select({
            "select",
            "commentaries_id, commentaries_time, post_id, commentaries_name, commentaries_content",
            "from five_commentaries",
            "where post_id = #{postId,jdbcType=INTEGER} and commentaries_time = (select Max(commentaries_time) from five_commentaries where post_id = #{postId,jdbcType=INTEGER})"
    })
    @ResultMap("com.meilele.dao.czh.FiveCommentariesMapper.ResultMapWithBLOBs")
    FiveCommentaries selectByPrimaryId(Integer postId);

    int updateByPrimaryKeySelective(FiveCommentaries record);

    @Update({
        "update five_commentaries",
        "set commentaries_time = #{commentariesTime,jdbcType=TIMESTAMP},",
          "post_id = #{postId,jdbcType=INTEGER},",
          "commentaries_name = #{commentariesName,jdbcType=VARCHAR},",
          "commentaries_content = #{commentariesContent,jdbcType=LONGVARCHAR}",
        "where commentaries_id = #{commentariesId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(FiveCommentaries record);

    @Update({
        "update five_commentaries",
        "set commentaries_time = #{commentariesTime,jdbcType=TIMESTAMP},",
          "post_id = #{postId,jdbcType=INTEGER},",
          "commentaries_name = #{commentariesName,jdbcType=VARCHAR}",
        "where commentaries_id = #{commentariesId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(FiveCommentaries record);


    @Select({
            "select",
            "commentaries_id, commentaries_time, post_id, commentaries_name, commentaries_content",
            "from five_commentaries",
            "where post_id = #{postId,jdbcType=INTEGER} and commentaries_time =(select Max(commentaries_time) from five_commentaries where post_id = #{postId,jdbcType=INTEGER})"
    })
    @ResultMap("com.meilele.dao.czh.FiveCommentariesMapper.ResultMapWithBLOBs")
    List<FiveCommentaries> selectByPrimarypId(Integer postId);

    @Select({
            "select",
            "commentaries_id, commentaries_time, post_id, commentaries_name, commentaries_content",
            "from five_commentaries",
            "where post_id = #{postId,jdbcType=INTEGER} "
    })
    @ResultMap("com.meilele.dao.czh.FiveCommentariesMapper.ResultMapWithBLOBs")
    List<FiveCommentaries> selectByPrimarycId(Integer postId);
}